/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.integralbusiness.handler;

import com.fulihui.integral.core.enums.ISAccountType;
import com.fulihui.integral.core.enums.ISChannelType;
import com.fulihui.integral.core.request.RewardPointsReq;
import com.fulihui.integral.core.result.ISUserBehaviorResult;
import com.fulihui.integralbusiness.constants.IntegralBusinessFlags;
import org.near.toolkit.common.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 有益反馈 积分处理器
 * @author zhangyingjie
 * @version $Id: v 0.1 2017年05月16日 15:27 zhangyingjie Exp $
 */
@Component("goodFeedbackIntegralBusinessHandler")
public class GoodFeedbackIntegralBusinessHandler extends AbstractIntegralBusinessHandler{
    private transient final Logger log = LoggerFactory.getLogger(getClass());

    @Override
    public void handle(Map<String, Object> msg) {
        String userId = msg.get("userId").toString();
        if (StringUtil.isBlank(userId)) {
            return;
        }
        String outTradeNo = msg.get("outTradeNo").toString();
        RewardPointsReq rewardPointsReq = new RewardPointsReq();
        rewardPointsReq.setUserId(userId);
        rewardPointsReq.setChannel(ISChannelType.FEEDBACK.getCode());
        rewardPointsReq.setIsAccountType(ISAccountType.BASE_JIFEN.getCode());
        rewardPointsReq.setOutTradeNo(outTradeNo);
        ISUserBehaviorResult result = userBehaviorService.rewardPoints(rewardPointsReq);
        if (result.getErrcode()!=0){
            log.error("goodFeedbackIntegralBusinessHandler有益返回发放积分有误userid:{}",userId);
        }
    }
    @Override
    IntegralBusinessFlags getFlag() {
        return IntegralBusinessFlags.GOOD_FEEDBACK;
    }
}
